package org.amj.srt;

import java.util.ArrayList;
import java.util.List;

public class Srt {
	private List<SrtEntry> entries = new ArrayList<SrtEntry>();

	public List<SrtEntry> getEntries() {
		return entries;
	}

	public void setEntries(List<SrtEntry> entries) {
		this.entries = entries;
	}

	public static Srt createFromText(String txt) {
		return null;
	}
	
	public String toSrtText(int startIndex) {
		StringBuilder sb = new StringBuilder();
		int index = startIndex;
		for (SrtEntry entry : entries) {
			sb.append(entry.toSrtEntry(index));
			index++;
		}
		
		return sb.toString();
	}

	public String toSrtText() {
		return toSrtText(1);
	}
	
	public void shortenEnteries(int charCount) {
		SrtEntry[] array = entries.toArray(new SrtEntry[0]);
		for (int i = 0; i < array.length; i++) {
			array[i].shortenEntry(charCount);
		}
	}

	public SrtEntry newEntry(int sh, int sm, int ss, int smi, int eh, int em, int es,
			int emi, String text) {
		SrtEntry e = new SrtEntry(this);
		e.getStart().setAll(sh, sm, ss, smi);
		e.getEnd().setAll(eh, em, es, emi);
		e.setText(text);
		return e;
	}
	
	public SrtEntry newEntry(int startSeconds , int endSeconds, String text) {
		SrtEntry e = new SrtEntry(this);
		e.getStart().setTotalSecond(startSeconds);
		e.getEnd().setTotalSecond(endSeconds);
		e.setText(text);
		return e;
	}
	
	public void shift(int seconds) {
		for (SrtEntry entry : entries) {
			entry.shift(seconds);			
		}
	}

}
